#include "ChessBoardWidget.h"
#include "ChessBoardImp.h"
#include "Chess.h"
#include "ChessBoard.h"
#include "GameActivity.h"
#include <QPoint>
#include <QPainter>
#include <QPaintEvent>
#include <QMouseEvent>
#include <iostream>
#include <vector>
#include <string>

void ChessBoardWidget::setChessBoard(ChessBoard *c){
    chessBoard = c;
}
void ChessBoardWidget::update(GameActivity* game){
    repaint();
}

void ChessBoardWidget::mousePressEvent(QMouseEvent *e){

    int x = e->x()-chessBoard->getChessBoardImp()->getAttribute("widthMargin");
    int y = e->y()-chessBoard->getChessBoardImp()->getAttribute("heightMargin");

    if(x<0 || y<0) return;

    QPoint p = chessBoard->getChessBoardImp()->getPosition(QPoint(x,y));
    x = p.x();
    y = p.y();
    if(x>=0 && y>=0)
        emit mouseClicked(y,x);

}

void ChessBoardWidget::paintEvent(QPaintEvent *e){

    chessBoard->getChessBoardImp()->paintBoard(this);

}

